<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>666</title>
</head>

<body>
    <div>
        <p>账 号：<input type="text" id="username"></p>
        <p>密 码：<input type="text" id="password"></p>
        <p>昵 称：<input type="text" id="nickname"></p>
        <p>年 龄：<input type="text" id="age"></p>
        <p>电话号：<input type="text" id="phone"></p>
        <p>头 像：<input type="text" id="avatar"></p>
        <p>邮 箱：<input type="text" id="email"></p>
        <p>性 别：<input type="text" id="sex"></p>
        <button id="addBtn">注册</button>
        <button id="loginbtn">已有账号，去登录</button>
    </div>
</body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="../public/static/js/$.js"></script>
<script src="../public/static/js/request.js"></script>
<script>

    $('addBtn').addEventListener('click', async () => {
        let params = {
            username: $('username').value,
            password: $('password').value,
            nickname: $('nickname').value,
            age: $('age').value,
            phone: $('phone').value,
            avatar: $('avatar').value,
            email: $('email').value,
            sex: $('sex').value,
        }
        let res = await request.post('/reg/register', params)
        console.log(res, 'res');
        if (res.data.code == 200) {
            alert(res.data.message)
            window.location.href = '../public/login.html'
        } else {
            alert(res.data.message)
        }
    })
    $('loginbtn').addEventListener('click', async () => {
        window.location.href = '../public/login.html'
    })
</script>

</html>